import os

from dotenv import load_dotenv
from langchain.agents import create_tool_calling_agent, tool, AgentExecutor
from langchain.chat_models import init_chat_model
from langchain_community.tools import TavilySearchResults
from langchain_core.prompts import ChatPromptTemplate
from langchain_ollama import ChatOllama

from tools.langchain_weather import get_weather

if __name__ == '__main__':
    load_dotenv(override=True)
    DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")
    model = ChatOllama(model="qwen3:latest", base_url="http://192.168.97.217:11434")
    prompt = ChatPromptTemplate.from_messages([
        ("system",
         "你是一名助人为乐的助手，并且可以调用工具进行网络搜索，获取实时信息"),
        ("human", "{input}"),
        ("placeholder", "{agent_scratchpad}"),
    ])
    search = TavilySearchResults(max_results=2)
    tools=[search]
    agent=create_tool_calling_agent(model, tools, prompt)
    agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
    result = agent_executor.invoke({"input": "瑞芯微第九届开发者大会在哪里举行"})
    print(result)
